package com.taoym.voucher.admin.controller;

import com.taoym.voucher.admin.entity.dto.XcxAddImageDTO;
import com.taoym.voucher.admin.entity.vo.XcxGetImageVO;
import com.taoym.voucher.admin.service.XcxImageService;
import com.taoym.voucher.common.response.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @coder taoym
 * @datetime 2021/9/3 9:12
 * @desc
 */
@RestController
@RequestMapping("/xcx/image")
@Api(tags = "小程序图片控制器")
public class XcxImageController {

    @Autowired
    private XcxImageService xcxImageService;

    @ApiOperation("查询图片列表")
    @GetMapping("/list")
    public Response<List<XcxGetImageVO>> listImages(@RequestParam @NotNull(message = "图片类型") Integer type) {
        return Response.success(xcxImageService.listImages(type));
    }

    @ApiOperation("添加图片")
    @PostMapping("/add")
    public Response<Integer> addImage(XcxAddImageDTO data) {
        return Response.success(xcxImageService.addImage(data));
    }

    @ApiOperation("删除图片")
    @GetMapping("/delete")
    public Response<Integer> deleteImage(@RequestParam @NotNull(message = "图片ID不能为空") Integer id,
                                         @RequestParam @NotBlank(message = "图片地址") String url) {
        return Response.success(xcxImageService.deleteImage(id, url));
    }
}
